package com.zhigh.urule.quickstart.test;

import com.bstek.urule.runtime.KnowledgePackage;
import com.bstek.urule.runtime.KnowledgeSession;
import com.bstek.urule.runtime.KnowledgeSessionFactory;
import com.bstek.urule.runtime.response.FlowExecutionResponse;
import com.bstek.urule.runtime.response.RuleExecutionResponse;
import com.bstek.urule.runtime.service.KnowledgeService;
import com.zhigh.urule.quickstart.Application;
import com.zhigh.urule.quickstart.urule.pojo.Customer;
import com.zhigh.urule.quickstart.urule.pojo.Order;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@SpringBootTest(classes = {Application.class}, properties = "server.port=9899")
public class SpringBootTestClass {

    @Resource(name = KnowledgeService.BEAN_ID)
    private KnowledgeService service;

    @Test
    void testKnowledgeService() throws Exception {
        KnowledgePackage knowledgePackage = service.getKnowledge("test_project/test_pck");
        KnowledgeSession session = KnowledgeSessionFactory.newKnowledgeSession(knowledgePackage);
        Order o1 = new Order("1", 1000.1f, 1);
        Order o2 = new Order("2", 1000.2f, 1);
        Order o3 = new Order("3", 3232.1f, 1);

        Customer customer = new Customer();
        customer.setOrders(Arrays.asList(o1, o2, o3));
        session.insert(customer);
//
//        Map<String,Object> params = new HashMap<>();
//        params.put("order_total_gt_1000", 0);
        // 执行知识包中的所有规则
        RuleExecutionResponse ruleExecutionResponse = session.fireRules();
        // 执行知识包中的指定规则流
        FlowExecutionResponse test_s_id_1 = session.startProcess("test_s_id_1");
        System.out.println(test_s_id_1);
        System.out.println(session.getParameter("order_total_gt_1000"));
    }
}
